﻿public class Solution {
    public int CoinChange(int[] coins, int amount)
    {
        int[] dp = new int[amount + 1];
        Array.Fill(dp, int.MaxValue);
        dp[0] = 0;

        for (int i = 0; i < coins.Length; i++)
        {
            for (int j = coins[i]; j <= amount; j++)
            {
                if (dp[j - coins[i]] != int.MaxValue) dp[j] = Math.Min(dp[j], dp[j - coins[i]] + 1);
            }
        }

        if (dp[amount] == int.MaxValue) return -1;
        return dp[amount];
    }

    public static void Main(string[] args)
    {
        int[] coins = [1, 2, 5];
        int amount = 11;

        Solution solution = new Solution();
        int res = solution.CoinChange(coins, amount);
        Console.WriteLine(res);
    }
}